package com.cskaoyan.utils;

import com.cskaoyan.constants.MallConstant;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

//md5加密
public class MD5 {
    public static String EnCode(String source) {
        if (source == null || source.length() == 0) {
            throw new RuntimeException(MallConstant.MESSAGE_STRING_INVAL_IDATE);
        }
        String algorithm = "md5";
        try {
            MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
            byte[] sourceBytes = source.getBytes();
            byte[] digest = messageDigest.digest(sourceBytes);
            int signum = 1;
            BigInteger bigInteger = new BigInteger(signum,digest);
            int radix = 16;
            String encode = bigInteger.toString(radix).toUpperCase();
            return encode;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
}
